/*******************************************************/
/*******************************************************/
/**** PART 4.1: APPENDIX TABLES - SUPLEMENTED SAMPLE****/
/*******************************************************/
/*******************************************************/


******************************************************
*** ABILITY SORTING (OVERALL SELECTION CHECK) ***
*** (SUPPLEMENTED SAMPLE) ***
*******************************************************

	forvalues i = 0/1{
	reg braven_sd biat_ethnic male ageinm s_ref_exposure csize i.grade1 i.b_schoolid urfa if refugee==`i', cluster(b_classid)
	estimates store spec1`i'
	scalar i1=e(r2)
	test biat_ethnic=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec1`i'
	estadd scalar pr2=i1 : spec1`i'

	** teacher demographics 

	reg braven_sd biat_ethnic male ageinm s_ref_exposure baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured btsurvey_16_refprop csize i.grade1 i.b_schoolid urfa if refugee==`i', cluster(b_classid)
	estimates store spec2`i'
	scalar i1=e(r2)
	test biat_ethnic=baseline_tmale=baseline_tage=baseline_texperience=tmarried=baseline_tchildnum=ttenured=btsurvey_16_refprop=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec2`i'
	estadd scalar pr2=i1 : spec2`i'

	** teacher demographics+cognition 

	reg braven_sd biat_ethnic male ageinm s_ref_exposure baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured btsurvey_16_refprop btraven_sd bteyes_sd csize i.grade1 i.b_schoolid urfa if refugee==`i', cluster(b_classid)
	estimates store spec3`i'
	scalar i1=e(r2)
	test biat_ethnic=baseline_tmale=baseline_tage=baseline_texperience=tmarried=baseline_tchildnum=ttenured=btraven_sd=bteyes_sd=btsurvey_16_refprop=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec3`i'
	estadd scalar pr2=i1 : spec3`i'

	** teacher demograpgics+cognition+styles  

	reg braven_sd biat_ethnic male ageinm s_ref_exposure baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured btsurvey_16_refprop btraven_sd bteyes_sd b_gms b_pedagogy b_modern b_extrinsic b_warmth b_competence b_idealism csize i.grade1 i.b_schoolid urfa if refugee==`i', cluster(b_classid)
	estimates store spec4`i'
	scalar i1=e(r2)
	test biat_ethnic=baseline_tmale=baseline_tage=baseline_texperience=tmarried=baseline_tchildnum=ttenured=btsurvey_16_refprop=btraven_sd=bteyes_sd=b_gms=b_pedagogy=b_modern=b_extrinsic=b_warmth=b_competence=b_idealism=0
	scalar i2=r(p)
	estadd scalar pr1=i2 : spec4`i'
	estadd scalar pr2=i1 : spec4`i'
	}

	#delimit ;
	esttab spec10 spec11 spec20 spec21 spec30 spec31 spec40 spec41  using "$path2/appendix_tableA1.tex",  replace label compress b(%8.2f) se(2) noconstant
	nonumbers keep(male ageinm s_ref_exposure biat_ethnic baseline_tmale baseline_tage baseline_texperience tmarried baseline_tchildnum ttenured  bteyes_sd btraven_sd b_gms b_pedagogy b_modern b_extrinsic b_warmth b_competence b_idealism btsurvey_16_refprop)
	coeflabels(male "Male" ageinm "Student Age in Months" biat_ethnic "Teacher Ethnic Bias" s_ref_exposure "\# of Semesters exposed to Refugees" csize "Class Size" baseline_tmale "\addlinespace[1mm] Male Teacher" tmarried "Married Teacher" ttenured "Tenured Teacher" baseline_tage "Teacher Age" baseline_texperience "Years of Experience" baseline_tchildnum "Number of Children" bteyes_sd "Teacher Cognitive Empathy Score" btraven_sd "\addlinespace[1mm] Teacher Raven Score"  b_gms "\addlinespace[1mm] Growth Mindset" b_pedagogy "Inquiry-based Pedagogy" b_modern "Modern Teaching" b_extrinsic "Extrinsic Motivation" b_warmth "Warmth" b_competence "\addlinespace[1mm] Competence" b_idealism "Professional Satisfaction" btsurvey_16_refprop "Desired Work Province - \% of refugee")
	star(* 0.10 ** 0.05 *** 0.01) nonotes 
	s(N pr1 pr2, fmt(%9.0g %9.3f %9.3f) labels("N" "P-Value of Joint Significance" "R-Squared"))
	nogaps
	mtitles ("Host" "Refugee" "Host" "Refugee" "Host" "Refugee" "Host" "Refugee")
	mgroups("(1)" "(2)" "(3)" "(4)", pattern(1 0 1 0 1 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
	substitute("&\multicolumn{2}{S}{" "\multicolumn{2}{c}{")
	refcat(baseline_tmale "\textbf{Teacher Demographics:}" b_gms "\addlinespace[1.5mm] \textbf{Teaching Styles:}"  btraven_sd "\addlinespace[1.5mm] \textbf{Teacher Cognition:}" b_competence "\textbf{Teacher Motivation:}", nolabel)
	;
	#delimit cr
	eststo clear


************************************************
*** SOCIAL TIES IN CLASSROOMS W/ NO REFUGEES *** 
*** (NO REFUGEE HOST CHECK) ***
************************************************

	** Covariate set 
	
	global covar1 male ageinm braven_sd beyes_sd baseline_tmale tmarried baseline_tchildnum ttenured baseline_tage baseline_texperience bteyes_sd btraven_sd b_gms b_pedagogy b_modern b_extrinsic b_warmth b_competence b_idealism csize refshare astudent s_ref_exposure

	** Analysis

	local i = 1
	foreach depvar in bnode_in_friend support_received support_provided study_received study_provided bturk_std bmath_st{
	reg `depvar' i.sample0##c.biat_ethnic $covar1 i.grade1 i.b_schoolid if refugee==0 & (sample1==1 |sample0==1), cluster(b_classid)
	estimates store spec`i'a
	local i = `i'+1
	}


		#delimit ;
		esttab spec1a  spec2a  spec3a  spec4a  spec5a 
		using "$path2/appendix_tableA6.tex",  
		keep (biat_ethnic 1.sample0#c.biat_ethnic)
		order(biat_ethnic 1.sample0#c.biat_ethnic)
        coeflabels(biat_ethnic "Teacher Ethnic Bias" 1.sample0#c.biat_ethnic "Teacher Ethnic Bias*No Refugee in Class")
		replace compress b(%8.2f) se(2)  noconstant nonumbers nobaselevels		
		
		star(* 0.10 ** 0.05 *** 0.01) nonotes 
		s(N, fmt(%9.0g %9.3f %9.3f %9.3f) labels("N"))
		nogaps		
		mtitles ( "Friendship" "E.S. Received" "E.S. Provided" "A.S. Received" "A.S. Provided")
		;
		#delimit cr	
		


